﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace _1vs100
{
    /// <summary>
    /// Interaction logic for Options.xaml
    /// </summary>
    public partial class Options : Window
    {
        Window1 gameWindow;
        public CheckBox chkTimer;

        public Options()
        {   
            InitializeComponent();
            setProperties();
        }

        /****************************************************Private Methods******************************************************************/

        private void setProperties()
        {
            chkTimer = new CheckBox();
            chkTimer.Name = "chkTimer";
            chkTimer.Width = 60;
            chkTimer.HorizontalAlignment = HorizontalAlignment.Right;
            chkTimer.Margin = new Thickness(0, 70, 125, 60);
            chkTimer.IsChecked = true;
            chkTimer.Content = "Timer";
            grdOptions.Children.Add(chkTimer);

            chkTimer.Unchecked += new RoutedEventHandler(chkTimer_Unchecked);
            chkTimer.Checked += new RoutedEventHandler(chkTimer_Checked);

            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            txtName.Focus();
        }

        /****************************************************Event Handling Methods*************************************************************/

        void chkTimer_Checked(object sender, RoutedEventArgs e)
        {
            lblTimer.Visibility = Visibility.Visible;
            lstTimer.Visibility = Visibility.Visible;
        }

        void chkTimer_Unchecked(object sender, RoutedEventArgs e)
        {
            lblTimer.Visibility = Visibility.Hidden;
            lstTimer.Visibility = Visibility.Hidden;
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Shutdown();
        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            if (txtName.Text == "" || lstDifficulty.SelectedIndex == 0 || ((Boolean)chkTimer.IsChecked && lstTimer.SelectedIndex == 0))
            {
                MessageBox.Show("Please select all fields", "Invalid Fields");
                return;
            }

            if ((Boolean)chkTimer.IsChecked)
            {
                ComboBoxItem tempItemTimer = (ComboBoxItem)(lstTimer.SelectedItem);
                String tempStringTimer = tempItemTimer.Content.ToString().Substring(0, 2);
                double tempTimer = Convert.ToDouble(tempStringTimer);
                ((App)Application.Current).currentGame.currentRules.Timer = tempTimer;
            }
            else
            {
                ((App)Application.Current).currentGame.timer = false;
            }
            ComboBoxItem tempItemDiff = (ComboBoxItem)(lstDifficulty.SelectedItem);

            ((App)Application.Current).currentGame.currentPlayer.Name = txtName.Text;
            ((App)Application.Current).currentGame.currentRules.Difficulty = tempItemDiff.Content.ToString();

            gameWindow = new Window1();
            gameWindow.Show();
            
            this.Visibility = Visibility.Hidden;
        }

    }
}
